from aip import AipOcr
from aip import AipSpeech

""" 你的 APPID AK SK """
APP_ID = '82268685'
API_KEY = '4nTnWx8mHRDmwranOe67SFUa'
SECRET_KEY = 'mxg0kItGpSPTWtDJQcZDdkZVOFzWI8Ix'

client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
client1 = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
""" 读取文件 """
def get_file_content(filePath):
  with open(filePath, "rb") as fp:
     return fp.read()

image = get_file_content('1.jpg ')

# 调用通用文字识别（标准版）
res_image = client.basicGeneral(image)
#print(res_image['words_result'])
lines=res_image['words_result']
text=''
for a in lines:
    text=text+a['words']
print(text)

result  = client1.synthesis(text, 'zh', 1, {
    'vol': 5,
})

# 识别正确返回语音二进制 错误则返回dict 参照下面错误码
if not isinstance(result, dict):
    with open('audio.mp3', 'wb') as f:
        f.write(result)
